package com.supply.dl.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.supply.dl.R;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 创建领料单成功 页面
 * <p>
 * Author: tian <br>
 * Time: 2018/5/9 16:40
 */
public class CreateMaterialSuccessActivity extends BaseActivity {

    @BindView(R.id.number_tv)
    TextView number_tv;

    /**
     * 领料单号
     */
    private String orderNo;


    @Override
    protected int getLayoutResource() {
        return R.layout.activity_create_material_success;
    }

    @Override
    protected void initView() {
        showLeftBack();
        setTitleShow("创建成功");

        orderNo = getIntent().getStringExtra("orderNo");
        number_tv.setText(orderNo);

    }

    @OnClick({R.id.copy_btn, R.id.back_list_tv})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.copy_btn:
                copyText(number_tv.getText().toString());
                break;
            case R.id.back_list_tv:
                finish();
                break;
        }
    }

    /**
     * 文本复制
     *
     * @param textCopy
     */
    public void copyText(String textCopy) {
        if (android.os.Build.VERSION.SDK_INT <= 11) {
            android.content.ClipboardManager c = (android.content.ClipboardManager)
                    getSystemService(Context.CLIPBOARD_SERVICE);
            c.setText(textCopy);

        } else {
            //获取剪贴板管理器：
            ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            // 创建普通字符型ClipData
            ClipData mClipData = ClipData.newPlainText("Label", textCopy);
            // 将ClipData内容放到系统剪贴板里。
            cm.setPrimaryClip(mClipData);
        }

        Toast.makeText(this, "复制成功", Toast.LENGTH_SHORT).show();
    }

}
